
/*
又拍云上传图片
 */
import 'package:dio/dio.dart';
import 'package:xsdk_flutter/xsdk/utils/http/x_utils_http.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_log.dart';

abstract class XYoupaiyunUtils{

  static final Dio _dio = Dio();

  //
  static void uploadFile(
      {
        required String url,
        required String filePath,
        required String policy,
        required String signature,
        required XHttpCallbackSucceed succeed,
        required XHttpCallbackFailed failed,
      }
      ) async{

    Map<String,dynamic> fromParams={};

    fromParams['policy']=policy;
    fromParams['signature']=signature;
    fromParams['file']=await MultipartFile.fromFile(
      filePath,
    );

    _dio.options.headers= {'x-upyun-api-version':'2'};
    FormData formData = FormData.fromMap(fromParams);
    _dio.post(url, data: formData).then((Response response){
      XLogUtils.printLog('----upload,response=$response.data');

      if(200==response.statusCode){
        String result=response.data?.toString()??'';
        Headers headers=response.headers;

        //通知
        succeed(result,headers.map);

      }else{

        failed('${response.statusCode??-1}',response.statusMessage??'');
      }
    }).catchError((e){
      failed('-1', '$e');
    });



  }




}
